package org.luxor.commons.rabbitmq.service.queue;

import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author Mr.Yan  @date 2019/10/16$
 */
@Component
@RabbitListener(queuesToDeclare = @Queue("queue.payment"))
public class QueueReceiver {
    private static final Logger log = LoggerFactory.getLogger(QueueReceiver.class);

    //绑定队列名称
    @RabbitHandler
    public void receiveQueue(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException {
        log.info("<<< 收到一个QUEUE消息. [{}] ", message);
        // 确认消息
        channel.basicAck(deliveryTag, false);
    }

}